package com.jeeplus.common.json;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jeeplus.core.mapper.JsonMapper;

import java.util.LinkedHashMap;

/**
 * @author Administrator
 * @title: ReturnJson
 * @projectName JeePlus
 * @description: TODO
 * @date 2019/10/2710:56
 */

public class ReturnJson {
    private Integer code=200;
    private String info="";
    private Object data=null;
    public void setCode(Integer code){
        this.code=code;
    }
    public Integer getCode(){
        return this.code;
    }
    public void setInfo(String info){
        this.info=info;
    }
    public String getInfo(){
        return this.info;
    }
    public void setData(Object data){
        this.data=data;
    }
    public Object getData(){
        return this.data;
    }
    private LinkedHashMap<String, Object> body = new LinkedHashMap<String, Object>();//封装json的map

    public LinkedHashMap<String, Object> getBody() {
        return body;
    }

    public void setBody(LinkedHashMap<String, Object> body) {
        this.body = body;
    }

    public void put(String key, Object value) {//向json中添加属性，在js中访问，请调用data.map.key
        body.put(key, value);
    }

    public void remove(String key) {
        body.remove(key);
    }
    @JsonIgnore//返回对象时忽略此属性
    public String getJsonStr() {//返回json字符串数组，将访问msg和key的方式统一化，都使用data.key的方式直接访问。

        String json = JsonMapper.getInstance().toJson(this);
        return json;
    }
}
